# !/usr/bin/env python
# -*- coding: utf-8 -*-
# @File  : Flask-SocketIO实现.py
# @Author: dongguangwen
# @Date  : 2025-01-05 14:28
from flask import Flask
from flask_socketio import SocketIO


app = Flask(__name__)
socketio = SocketIO(app)


@app.route('/')
def index():
    return "WebSocket Server is running"


@socketio.on('message')
def handle_message(message):
    print(f"Received: {message}")
    socketio.send(f"Echo: {message}")


if __name__ == '__main__':
    socketio.run(app, host='localhost', port=6789, allow_unsafe_werkzeug=True)
